<%--
  Created by IntelliJ IDEA.
  User: User
  Date: 2024/5/16
  Time: 15:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
    <head>
        <title>Title</title>
        <script src="${pageContext.request.contextPath}/js/jquery-3.4.1.js"></script>
        <script>
            $(function () {
                $("a[name='modifyCart']").click(function () {
                    let id = $(this).attr("data-id");

                    // console.log($(选择器,指定范围).val())
                    let num = $("input[type='text']", $(this).parent().parent()).val();
                    location.href = "${pageContext.request.contextPath}/modify.cart?id=" + id + "&num=" + num;
                });

                $("#removeByIds").click(function () {
                    $("#cartForm").submit();
                });
            });
        </script>
    </head>
    <body>
        <form id="cartForm" action="${pageContext.request.contextPath}/removeByIds.cart" method="post">
            <table>
                <thead>
                    <tr>
                        <th><input type="checkbox" id="all"></th>
                        <th>序号</th>
                        <th>商品名称</th>
                        <th>商品数量</th>
                        <th>商品总价</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${cart.items}" var="item" varStatus="i">
                        <tr>
                            <td><input type="checkbox" name="id" value="${item.product.id}"></td>
                            <td>${i.index+1}</td>
                            <td>${item.product.name}</td>
                            <td><input type="text" value="${item.num}"></td>
                            <td>${item.price}</td>
                            <td>
                                <a href="javascript:;" name="modifyCart" data-id="${item.product.id}">修改</a>
                                <a href="${pageContext.request.contextPath}/removeById.cart?id=${item.product.id}" onclick="return confirm('确定删除吗?')">删除</a>
                            </td>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
        </form>
        ---------------------------------------------
        <br>
        总计:${cart.price}元
        <br>
        <a href="javascript:;" id="removeByIds">删除选中项</a>
        <a href="${pageContext.request.contextPath}/clear.cart">清空购物车</a>
        <a href="${pageContext.request.contextPath}/findAll.product">继续购物</a>
        <a href="${pageContext.request.contextPath}/jsp/confirm.jsp">结算</a>
        <span style="color:red;">
            ${cartMsg}
        </span>


        <div>
            <p>p</p>
        </div>
        <p>p2</p>
    </body>
</html>
